#include "players.h"

/*Player-------------------------------
 * Its a class that represents a player.
 * It stores all of its fleets,
 * resourcces, etc and handles updates at
 *  the end of the turn.
 ------------------------------------*/
//constructors---------------
Players::player::player(int id, string name) {
    playerId = id;
    playerName = name;
    endedTurn = false;
}
Players::player::~player() {
}
//access---------------------
string  Players::player::gName(){
    return playerName;
}
Players::fleetmanager* Players::player::gFleetManager() {
    endedTurn = true;
    return &Fleets;
}
bool Players::player::played() {
    return endedTurn;
}
//manips---------------------
void Players::player::reset() {
    endedTurn = false;
}
void Players::player::endTurn() {
    Fleets.endTurn();
}
/*playerLib--------------------------------------
 * the player library. It keeps track of the current
 * turn, whose next, and updating bases at the last
 * turn.
 ----------------------------------------------*/
//constructors----------------
Players::playerLib::playerLib() {
    currentPlayer = 0;
}
Players::playerLib::~playerLib() {
}
void Players::playerLib::newPlayer(string str){
    player p(players.size(), str);
    players.push_back(p);
}
//access----------------------
Players::player* Players::playerLib::gPlayer(int id){
    if(id >= 0 && id < players.size()) return &players[id];
    return NULL;
}
Players::player* Players::playerLib::gCurentPlayer() {
    return &players[currentPlayer];
}
int Players::playerLib::gCurrentPlayerId() {
    return currentPlayer;
}
//manips---------------------
void Players::playerLib::setTurnOrderPolicy(turnOrder o) {
    orderPolicy = o;
}
void Players::playerLib::endTurn() {
    players[currentPlayer].endTurn();
    int start = currentPlayer;
    if (orderPolicy == random) start = rand();
    while (players[currentPlayer].played()) {
        start = currentPlayer++;
        if (currentPlayer >= players.size()) currentPlayer = 0;
        if (start == currentPlayer) resetAll();
    }
}
void Players::playerLib::resetAll() {
    for (int i = 0; i < players.size(); i++) {
        players[i].reset();
    }
}
#include "players.h"

/*fleetManager-----------------------------------
 * the fleet manager holds all the top level fleets
 * available to the player.  mostly used for displaying
 * information, rather than maniopulating individual
 * units.  However it does have methods to access
 * specific Units.  Mostly made to make fleet-level
 * manipulatoion easier
 * --------------------------------------------*/
//constructors---------------
Players::fleetmanager::fleetmanager() {

}
Players::fleetmanager::~fleetmanager() {

}
//access---------------------
int Players::fleetmanager::activeCells() {
    map<int, Units::unitgroup*>::iterator itr;
    int size = 0;
    for(itr = fleetlist.begin(); itr != fleetlist.end(); itr++){
        size += itr->second->numUnits();
    }
}
int Players::fleetmanager::activeFleets() {
    return fleetlist.size();
}
Units::unit* Players::fleetmanager::gCell(int x, int y) {
    Units::unitLib::staticLib()->getUnit(x, y);
}
Units::unitgroup* Players::fleetmanager::gFleet(int id) {
    return fleetlist[id];
}
Units::unitgroup* Players::fleetmanager::gFleet(int x, int y) {
    return gCell(x,y)->getParent();
}
//manips---------------------
void Players::fleetmanager::endTurn(){

}
bool Players::fleetmanager::killFleet(int id){
    Units::unitgroup* u = fleetlist[id];
    list<Units::unit*>::iterator itr = u->unitIter();
    for(int i = 0; i < u->numUnits(); i++, itr++){
        u->remUnit(*itr);
    }
    delete u;
    fleetlist.erase(id);
}
bool Players::fleetmanager::killFleet(int x, int y){

}
int Players::fleetmanager::newFleet(){

}
void Players::fleetmanager::assignFleet(Units::unitgroup* ugp, Units::unit* u){

}
Units::unit* Players::fleetmanager::newCell(Units::unit* cell){

}
Units::unit* Players::fleetmanager::newCell(int fleetId, int x, int y){

}
